package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Promotionaloffertype;
import com.restaurant.service.PromotionaloffertypeService;

public class PromotionaloffertypeServiceImpl implements PromotionaloffertypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffertype addOrModify( Promotionaloffertype objPromotionaloffertype ) {
       return ( Promotionaloffertype ) hibernateTemplate.merge( objPromotionaloffertype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffertype deleteRecord( Promotionaloffertype objPromotionaloffertype ) {
       hibernateTemplate.delete( objPromotionaloffertype );
       return objPromotionaloffertype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffertype modifyRecord( Promotionaloffertype objPromotionaloffertype ) {
       return ( Promotionaloffertype ) hibernateTemplate.merge( objPromotionaloffertype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Promotionaloffertype> loadAll() {
       return (List<Promotionaloffertype>)hibernateTemplate.findByNamedQuery( "Promotionaloffertype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffertype loadByPrimaryKey( Long primaryKey ) {
       return (Promotionaloffertype) hibernateTemplate.get( Promotionaloffertype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Promotionaloffertype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Promotionaloffertype> loadByHql(String query) {
       return ( List<Promotionaloffertype> ) hibernateTemplate.find( query );
   }
}